package com.yang.controller.admin;

import com.yang.bean.MarketCategory;
import com.yang.bean.common.BaseRespVo;
import com.yang.bean.common.CommonData;
import com.yang.bean.yvo.Category;
import com.yang.service.admin.GoodsCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author: 杨庆  商品类目的的管理
 * @since: 2022.9.6 17:46
 * @description:
 */
@RestController
@RequestMapping("admin/category")
public class AdminCategoryController {

    @Autowired
    GoodsCategoryService goodsCategoryService;

    /**
    * @description: 显示所有的商品类目的信息
    * @return: com.yang.bean.common.BaseRespVo
    * @author: 杨庆
    * @time: 2022.9.6 23:15
     */
    @RequestMapping("list")
    public BaseRespVo list(){
        CommonData commonData = goodsCategoryService.selectAll();
        return BaseRespVo.ok(commonData);
    }


    /**
    * @description: l1显示所有的类别信息
    * @return: com.yang.bean.common.BaseRespVo
    * @author: 杨庆
    * @time: 2022.9.6 21:45
     */
    @RequestMapping("l1")
    public BaseRespVo catelist(){
        CommonData commonData = goodsCategoryService.selectCateList();
        return BaseRespVo.ok(commonData);
    }

    /**
    * @description: 修改商品的类目信息
    [category]
    * @return: com.yang.bean.common.BaseRespVo
    * @author: 杨庆
    * @time: 2022.9.6 23:17
     */
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Category category){
        int code = goodsCategoryService.updateCategory(category);
        if (code == 200) {
            return  BaseRespVo.ok();
        }
        return  BaseRespVo.invalidParameter("失败");
    }


    /**
    * @description: 商品类目的删除
    [category]
    * @return: com.yang.bean.common.BaseRespVo
    * @author: 杨庆
    * @time: 2022.9.6 23:14
     */
    @RequestMapping("delete")
    public BaseRespVo deleteCategory(@RequestBody Category category){
       int code  =  goodsCategoryService.deleteCategory(category);
        if (code == 200) {
            return  BaseRespVo.ok();
        }
        return  BaseRespVo.invalidParameter("失败");
    }


    @RequestMapping("create")
    public BaseRespVo createCategory(@RequestBody MarketCategory marketStorage) {
        MarketCategory m1 = goodsCategoryService.createCategory(marketStorage);
        return BaseRespVo.ok(m1);
    }






}
